#pragma once
#include"Common.h"
#include"ObjectPool.h"
#include"PageMap.h"
class PageCache
{
public:
	static PageCache* GetInstance()
	{
		return &_sInst;
	}

	//获取从对象到span的映射
	Span* MapObjectTospan(void* obj);

	//释放空闲span回到Pagecache，并合并相邻的span
	void ReleaseSpanToPagecache(Span*span);
	// 获取⼀个K⻚的span
	Span* NewSpan(size_t k);

	/*void Lock()
	{
		pagemtx.lock();
	}*/

	/*void unLock()
	{
		pagemtx.unlock();
	}*/
	std::mutex _pageMtx;
private:
	PageCache()
	{}
	PageCache(const PageCache&) = delete;
	//PageCache& operator=(const PageCache&) = delete;
	SpanList _spanLists[NPAGES];
	
	static PageCache _sInst;
	std::unordered_map<PAGE_ID, Span*>_idSpanMap;	


	ObjectPool<Span> spanPool;

	//std::unordered_map<PAGE_ID, size_t>_idSizeMap;
	//TCMalloc_PageMap1<32 - PAGE_SHIFT>_idSpanMap;
};
